import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"
import CacheLocal from "@/utils/cacheLocal"
const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/main"
  },
  {
    path: "/main",
    name: "main",
    component: () => import("@/views/main/index.vue"),
    children: [
      // {
      //   path:"list/pandaKill",
      //   component: () => import("@/views/list/pandaKill.vue")
      // }
    ]
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue")
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to) => {
  if (to.path !== "/login") {
    const token = CacheLocal.getItem("LSToken")
    if (!token) {
      router.push("/login")
    }
  }
  // return
})

export default router
